package com.screen.screendisplay.service.impl.coal;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.screen.screendisplay.entity.coal.CoalOpermonRtSlopeAlarm;
import com.screen.screendisplay.mapper.coal.CoalOpermonRtSlopeAlarmMapper;
import com.screen.screendisplay.service.coal.CoalOpermonRtSlopeAlarmService;
import com.screen.screendisplay.vo.coal.CoalSlopeAlertVO;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 运行检测边坡告警表 服务实现类
 * </p>
 *
 * @author xuesong
 * @since 2025-08-23
 */
@Service
public class CoalOpermonRtSlopeAlarmServiceImpl extends ServiceImpl<CoalOpermonRtSlopeAlarmMapper, CoalOpermonRtSlopeAlarm> implements CoalOpermonRtSlopeAlarmService {

    @Override
    public List<CoalSlopeAlertVO> getSlopeAlerts(Integer year) {
        // 查询最近10条告警数据，按告警时间降序排序
        LambdaQueryWrapper<CoalOpermonRtSlopeAlarm> wrapper = Wrappers.lambdaQuery();
        wrapper.orderByDesc(CoalOpermonRtSlopeAlarm::getAlarmTime)
               .last("LIMIT 10");
        
        List<CoalOpermonRtSlopeAlarm> alarmList = this.list(wrapper);
        
        // 转换为VO列表
        List<CoalSlopeAlertVO> resultList = new ArrayList<>();
        
        for (CoalOpermonRtSlopeAlarm alarm : alarmList) {
            CoalSlopeAlertVO vo = new CoalSlopeAlertVO();
            vo.setAlarmLocation(alarm.getAlarmLocation());
            vo.setAlarmTime(alarm.getAlarmTime());
            vo.setInstantRate(alarm.getInstantRate());
            vo.setAlarmRange(alarm.getAlarmRange());
            
            resultList.add(vo);
        }
        
        return resultList;
    }
}
